<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/login.css" />
	</head>
	<!-- 引入设置cookie的函数 -->
	<script src="../js/setcookie.js" type="text/javascript" charset="utf-8"></script>
	
	<body class="bodyAll">
		<div id="" class="loginBox">
			<div class="logal clean">
				<h3 class="active1">欢迎登录!</h3>
				<h3>欢迎注册!</h3>
			</div>

			<div class="formWide">
				<!-- 登录页面 -->
				<form class="formBox1 active2">
					账号:<input type="text" name="" id="userName" placeholder="请输入您的账号（即手机号）" value="" /><span id="error"></span><br>
					密码:<input type="password" name="" id="passWord" value="" /><span id="error"></span><br>
					<input type="button" name="" id="denglu" value="登录" />
				</form>
				<!-- 注册页面 -->
				<form class="formBox2">
					账号:<input type="text" name="" id="userName2" value="" placeholder="请输入您的手机号码" /><span id=""></span><br>
					密码:<input type="text" name="" id="passWord2" value="" /><span id=""></span><br>
					确认密码:<input type="text" id="passWord3"/><span id=""></span><br>
					<input type="button" name="" id="zhuce" value="注册" />
				</form>
			</div>
		</div>
		<script src="../lib/jquery/jquery.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/login.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			//	登录页面的点击事件
			$('#denglu').click(function(){
				$.ajax({
					type:'post',
					url:'/wty1',
					data:{
						username:$('#userName').val(),
						password:$('#passWord').val()
					},
					dataType:'JSON',  //传过来的json数据解析
					success:function(res){
						console.log(res)
						 if(res.code===0){
							alert('输入的用户名不存在或密码错误')
						 }else{
							
							$(location).attr("href","./index1.html");
							setCookie('username',1,86400) //存入一个cookie数据，第三个参数为设置失效时间为24小时后
						 }
					}
				})
			})
			
			//注册页点击事件
			$('#zhuce').click(function(){
				$.ajax({
					type:'post',
					url:'/wty2',
					data:{
						username:$('#userName2').val(),
						password:$('#passWord2').val()
					},
					dataType:'JSON',  //传过来的json数据解析
					success:function(res){
						console.log(res)
						if(res.code===2){
							alert('该账号已经被注册')
						}else if(res.code===3){
							alert('注册成功，快去登录吧')
						}
					}
				})
			})
		</script>
	</body>
</html>
